package com.winit.datasync.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Service;

import com.winit.datasync.service.MailService;
import com.winit.datasync.utils.ConstantUtils;
import com.winit.datasync.utils.DateUtil;

@Service("mailService")
public class MailServiceImpl implements MailService {
	private static Logger LOGGER = LoggerFactory
			.getLogger(MailServiceImpl.class);

	@Autowired
	private SimpleMailMessage mailMessage;
	@Autowired
	private JavaMailSenderImpl mailSender;

	@Override
	public void sendMail(String msg,String syncType) {
		try {
			mailMessage.setSubject(ConstantUtils.MAIL_START
					+ DateUtil.convertDateToString(new Date()));
			mailMessage.setText(syncType + ConstantUtils.MAIL_EXCEPTION + msg);
			mailSender.send(mailMessage);
		} catch (Exception e) {
			LOGGER.error(
					"MailServiceImpl sendMail exception:" + e.getMessage());

		}

	}

}
